home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / unix / c / chmod < prev    next >
Text File  |  1996-11-09  |  1KB  |  58 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/chmod,v $
  4.  * $Date: 1996/10/30 21:59:01 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: chmod,v $
  10.  * Revision 1.2  1996/10/30 21:59:01  unixlib
  11.  * Massive changes made by Nick Burret and Peter Burwood.
  12.  *
  13.  * Revision 1.1  1996/04/19 21:35:27  simon
  14.  * Initial revision
  15.  *
  16.  ***************************************************************************/
  17.  
  18. static const char rcs_id[] = "$Id: chmod,v 1.2 1996/10/30 21:59:01 unixlib Rel $";
  19.  
  20. #include <errno.h>
  21.  
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <unistd.h>
  25. #include <sys/os.h>
  26.  
  27. int
  28. chmod (const char *file, mode_t mode)
  29. {
  30.   int r[6];
  31.   _kernel_oserror *e;
  32.   char *f;
  33.  
  34.   f = __uname ((char *)file, 0);
  35.  
  36.   if (e = os_file (5, f, r))
  37.     {
  38.       __seterr (e);
  39.       return (-1);
  40.     }
  41.   if (!r[0])
  42.     {
  43.       errno = ENOENT;
  44.       return (-1);
  45.     }
  46.  
  47.   r[5] = (r[5] & 0xFFFFFF00) | ((mode & 0400) >> 8) | ((mode & 0200) >> 6) |
  48.     ((mode & 0004) << 2) | ((mode & 0002) << 4);
  49.  
  50.   if (e = os_file (1, f, r))
  51.     {
  52.       __seterr (e);
  53.       return (-1);
  54.     }
  55.  
  56.   return (0);
  57. }
  58.